﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;

namespace WebDemo.Filters
{
    public class ProfileAttribute : ActionFilterAttribute
    {
        private Stopwatch timer;
        
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            timer = Stopwatch.StartNew();
        }

        public override void OnActionExecuted(HttpActionExecutedContext filterContext)
        {
            timer.Stop();
            filterContext.Response.Headers.Add("EXT",timer.Elapsed.TotalMilliseconds.ToString());
        }
    }
}